import { Photos } from '@api/photos/schemas/photos.schema';
import { Prop, SchemaFactory, Schema } from '@nestjs/mongoose';
import * as mongoose from 'mongoose';
import { Document, Types, ObjectId } from 'mongoose';
import { User } from './user.schema';

export type UserFocusPhotosDocument = UserFocusPhotos & Document;

/**
 * 用户喜欢作品表
 */
@Schema()
export class UserFocusPhotos {
    /**
     * 用户id
     */
    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User', index: true })
    user: User | ObjectId;
    /**
     * 作品
     */
    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Photos', index: true })
    photos: Photos | ObjectId;
    /**
     * 创建时间
     */
    @Prop({
        default: Date.now,
    })
    createdAt: Date;
}

export const UserFocusPhotosSchema = SchemaFactory.createForClass(UserFocusPhotos);
UserFocusPhotosSchema.index({ user: 1, photos: 1 }, { unique: true });
